<?php
// +----------------------------------------------------------------------
// | Author: ZYN Fl
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Db;
class Banner extends Common
{
    public function index()
    {
    	$banner=Db::name('banner')->select();
        $this->assign("banner",$banner);
        $this->assign('a','Banner');
        return $this->fetch();
    }
    public function addlist()
    {
        $this->assign('a','Banner');
        return $this->fetch();
    }
    public function addxinx(){
        $file = request()->file('bimg');
        $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
        if($info){ 
            $data = array(
            'bimg' => $info->getSaveName()
            );
        $banner=Db::name('banner')->insert($data);
        if($banner){
           $this->redirect('Banner/index');
        }
        }else{
            echo $file->getError();
        }
    }
    //编辑信息
    public function update()
    {
        $bid = input('bid');
        $data=Db::name('banner')->where("bid='$bid'")->select();
        $this->assign('a','Banner');
        $this->assign("data",$data);
        return $this->fetch();
    }
    //保存信息
    public function xiugai(){
        $bid = input('bid');
        $bimg = input('bimg');
        $file = request()->file('bimg');
        if($file==null){
            $data =array(
                'bid' => $bid,
                'bimg' => $bimg
                );
        $banner=Db::name('banner')->where("bid='$bid'")->update($data);
        if($banner!==false){
           $this->redirect('Banner/index');
        }
        }else{
        $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
        if($info){ 
            $data = array(
            'bid' => $bid,   
            'bimg' => $info->getSaveName()
            );
        $banner=Db::name('banner')->where("bid='$bid'")->update($data);
        if($banner!==false){
           $this->redirect('Banner/index');
        }
        }else{
            echo $file->getError();
        }
        }
    }
    //删除
    public function del(){
        $bid = input('bid');
        $data = array(
            'bid' =>$bid
            );
        $del=Db::name('banner')->where("bid='$bid'")->delete($data);
        if($del){
            return 1;
        }
    }
}